package com.cjw.campus.generate;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

import java.util.Collections;

public class MybatisPlusGenerate {

    /**
     * 主入口函数
     * @param args
     */
    public static void main(String[] args) {
        String moduleName = "system";
        FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/micro_questions_answers?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false", "root", "root")
                .globalConfig(builder -> {
                    builder.enableSwagger().author("cjw") // 设置作者
                            .outputDir("D:/home/cjw/下载/generate"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.cjw.campus").moduleName(moduleName) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D:/home/cjw/下载/generate/com/cjw/campus/" + moduleName + "/mapper/xml")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("background_user_table","school_table","class_table","matriculation_year_table","student_table","teacher_table","subject_table")
                            .controllerBuilder().enableRestStyle()
                            .entityBuilder().idType(IdType.ASSIGN_ID).logicDeleteColumnName("delete_flag")
                            .addTableFills(new Column("create_time", FieldFill.INSERT),
                                    new Column("creator", FieldFill.INSERT),
                                    new Column("update_time", FieldFill.INSERT_UPDATE),
                                    new Column("updater", FieldFill.INSERT_UPDATE),
                                    new Column("delete_flag", FieldFill.INSERT)).enableLombok(); // 设置需要生成的表名
                    // .addTablePrefix("t_", "c_"); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}
